package com.spt.springbootzhsx.utils;

import com.spt.springbootzhsx.dao.OrderDao;
import com.spt.springbootzhsx.entity.Order;
import com.spt.springbootzhsx.entity.Plan;
import com.spt.springbootzhsx.mapper.OrderMapper;
import com.spt.springbootzhsx.mapper.PlanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;

@Component
public class TimeUtil {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private PlanMapper planMapper;

    @Scheduled(fixedRate = 30000)
    private void refrash(){
        ArrayList<Order> list=orderMapper.getAllOrderByOstate("未过期");
        Date now=new Date();
        for (Order order : list) {
            Plan plan=planMapper.getPlanByPid(order.getPid());
            if(plan.getPlayTime().getTime()<now.getTime()){
                orderMapper.updateOrderOstate(order.getOid(),"已过期");
            }
        }
    }
}
